//
//  App.m
//  IOSFrameWork
//
//  Created by 严贵敏 on 15/6/25.
//  Copyright (c) 2015年 严贵敏. All rights reserved.
//

#import "AppUI.h"
#import <objc/runtime.h>
#import <POP.h>
static char btnActionKey;
@implementation AppUI

+(UIView *)createViewWithSupeView:(UIView *)supeView
           andWithBackgroundColor:(UIColor *)color{
    
    UIView *view = [UIView new];
    view.backgroundColor = color;
    [supeView addSubview:view];
    return view;
    
}
+(UIView *)cellselectView{

    UIView *view=[UIView new];
    view.backgroundColor=RGB(250,250,250,1);
    return view;

}
+(UIView *)createCellLineViewWithSupeView:(UIView *)supeView{
   return [self createViewWithSupeView:supeView andWithBackgroundColor:[UIColor customLineGreyColor]];
}

+(UIButton *)createButtonWithBtnAction:(btnAction)Block{
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    objc_setAssociatedObject(btn, &btnActionKey, Block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

+(UIButton *)createCollectionButtonWithBtnAction:(btnAction)Block{
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    objc_setAssociatedObject(btn, &btnActionKey, Block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [btn addTarget:self action:@selector(CollectionbtnAction:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
}
+(void)CollectionbtnAction:(UIButton *)btn{
    if (btn.selected == YES) {
        [btn setSelected:NO];
    }else{
        [btn setSelected:YES];
    }
    btnAction block = (btnAction)objc_getAssociatedObject(btn, &btnActionKey);
    if (block) {
        block();
    }
}

+(UIButton *)createButtonWithText:(NSString *)text
                 andWithTextColor:(UIColor *)color
                 andWithFontfloat:(float)fontfloat
                 andWithBtnAction:(btnAction)Block{
    UIButton *btn=[self createButtonWithBtnAction:Block];
    [btn setTitle:text forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font=[UIFont systemFontOfSize:fontfloat];
    return btn;
}
+(UIButton *)createButtonWithSupeView:(UIView *)supeView
               andWithBackgroundColor:(UIColor *)color
                  andWithCornerRadius:(CGFloat)radius
                     andWithBtnAction:(btnAction)Block{
    UIButton *btn=[self createButtonWithBtnAction:Block];
    [btn setBackgroundColor:color];
    btn.layer.cornerRadius  = radius;
    btn.layer.masksToBounds = YES;
    [supeView addSubview:btn];
    return btn;
}

+(UIButton *)createButtonWithSupeView:(UIView *)supeView
                   andWithNormalImage:(UIImage *)normalImage
                   andWithSelectImage:(UIImage *)selectImage
                     andWithBtnAction:(btnAction)Block{
    UIButton *btn=[self createButtonWithBtnAction:Block];
    [btn setImage:normalImage forState:UIControlStateNormal];
    [btn setImage:selectImage forState:UIControlStateSelected];
    [supeView addSubview:btn];
    return btn;
}

+(void)btnAction:(UIButton *)btn{
    btnAction block = (btnAction)objc_getAssociatedObject(btn, &btnActionKey);
    if (block) {
        block();
    }
//    POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSubscaleXY];
//    scaleAnimation.velocity = [NSValue valueWithCGSize:CGSizeMake(5.f, 5.f)];
//    scaleAnimation.toValue  = [NSValue valueWithCGSize:CGSizeMake(1.0f, 1.0f)];
//    scaleAnimation.springBounciness = 18.0f;
//    [btn.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSpringAnimation"];
}
+(UIImageView *)createImageViewWithSupeView:(UIView *)supeView{

    UIImageView *ImageView = [[UIImageView alloc]init];
    [supeView addSubview:ImageView];
    return ImageView;
}
+(UIImageView *)createImageViewWithSupeView:(UIView *)supeView
                                 andWithUrl:(NSString *)url{
    UIImageView *ImageView = [[UIImageView alloc]init];
    [ImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:place_image02];
    [supeView addSubview:ImageView];
    return ImageView;
    
}

+(UIImageView *)createImageViewWithSupeView:(UIView *)supeView
                               andWithImage:(UIImage *)image{
    UIImageView *ImageView = [[UIImageView alloc]init];
    [supeView addSubview:ImageView];
    [ImageView setImage:image];
    return ImageView;
}

+(UILabel *)createLabelWithSupeView:(UIView *)supeView
                     andWiFontfloat:(float)fontfloat
                   andWithTextColor:(UIColor *)color{
    UILabel *lable=[[UILabel alloc]init];
    lable.font=[UIFont systemFontOfSize:fontfloat];
    lable.textColor=color;
    [supeView addSubview:lable];
    return lable;
}
+(UILabel *)createCellTitleLabelWithSupeView:(UIView *)supeView{
    
   return [self createLabelWithSupeView:supeView andWiFontfloat:16 andWithTextColor:[UIColor customTextBlackColor]];
}
+(UILabel *)createCellContentLabelWithSupeView:(UIView *)supeView{
    
    UILabel *lable=[self createLabelWithSupeView:supeView andWiFontfloat:14 andWithTextColor:[UIColor customTextGreyColor]];
//    lable.numberOfLines=2;
    return  lable;
}
+(UILabel *)createPayNowLabelWithSupeView:(UIView *)supeView{
    UILabel *lable=[[UILabel alloc]init];
    lable.font=[UIFont boldSystemFontOfSize:18];
    lable.textColor=[UIColor customTextOrangeColor];
    [supeView addSubview:lable];
    return lable;
}

+(void)initNavigationItem1:(UINavigationItem *)navigationItem andWithText:(NSString *)text  andIsRight:(BOOL)IsRight  withBlock:(btnAction)ActionBlock{
    UIButton *btn=[self createButtonWithText:text andWithTextColor:[UIColor customTextGreyColor] andWithFontfloat:14 andWithBtnAction:ActionBlock];
    btn.frame=CGRectMake(0, 0,44, 40);
    btn.titleLabel.textAlignment=NSTextAlignmentCenter;
     UIBarButtonItem *Item=[[UIBarButtonItem alloc]initWithCustomView:btn];
    if (IsRight) {
          navigationItem.rightBarButtonItem=Item;
    }else{
        navigationItem.leftBarButtonItem=Item;
    }
}
+(void)initNavigationItem:(UINavigationItem *)navigationItem andWithText:(NSString *)text andTextColor:(UIColor *)color andIsRight:(BOOL)IsRight  withBlock:(btnAction)ActionBlock{
    UIButton *btn=[self createButtonWithText:text andWithTextColor:color andWithFontfloat:18 andWithBtnAction:ActionBlock];
    btn.frame=CGRectMake(0,0,60,40);
    btn.titleLabel.textAlignment=NSTextAlignmentCenter;
    UIBarButtonItem *Item=[[UIBarButtonItem alloc]initWithCustomView:btn];
    if (IsRight) {
        navigationItem.rightBarButtonItem=Item;
    }else{
        navigationItem.leftBarButtonItem=Item;
    }
}
+(void)setBack:(UINavigationItem *)navigationItem{
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"";
//    backItem.tintColor=[UIColor customSelectColor];
    navigationItem.backBarButtonItem = backItem;
}
+(NSString *)GetImageWithAndHeightWithUrl:(NSString *)url andWidth:(float)width andWithHeigh:(float)height{

    NSString *imageWH=[NSString stringWithFormat:@"!w%f_h%f.jpg",width,height];
    NSString *Imageurl=[url stringByAppendingString:imageWH];
    return Imageurl;
}
@end
